<template>
  <view>
    <u-navbar title="新增企业资料"> </u-navbar>
    <formz ref="formz" :inputs="inputs" :data="data"></formz>

    <bottombox>
      <u-button
        type="primary"
        :loading="loading"
        text="保存数据"
        @click="onedit"
      ></u-button>
    </bottombox>
  </view>
</template>

<script>
import { createCompanyFile } from "@/api/company/companyFile";
export default {
  data() {
    return {
      data: {},
      loading: false,
      inputs: [
        {
          label: "部门",
          value: "deptId",
          type: "deptId",
          rules: [
            {
              required: true,
              trigger: "blur",
              message: "请选择部门",
            },
          ],
        },
        {
          label: "资料名称",
          value: "name",
          rules: [
            {
              required: true,
              trigger: "blur",
              message: "资料名称不能为空",
            },
          ],
        },
        {
          label: "资料类型",
          value: "dataType",
          type: "select",

          option:
            this.$store.state.dict.dictDatas[
              this.$store.state.dict.DICT_TYPE.BUSI_MANG_FILETYPE
            ],
          rules: [
            {
              required: true,
              trigger: "blur",
              message: "资料类型不能为空",
            },
          ],
        },
        {
          label: "文件路径",
          value: "file",
          type: "file",
          attrs: {
            accept: "file",
          },
          rules: [
            {
              required: true,
              trigger: "blur",
              message: "文件路径不能为空",
            },
          ],
        },
        {
          label: "开始日期",
          value: "startTime",
          type: "datetime",
        },
        {
          label: "到期日期",
          value: "endTime",
          type: "datetime",
        },
      ],
    };
  },

  methods: {
    async init() {
      // let data = await getCompanyInfo();
      // this.data = data.data;
    },
    async onedit() {
      let data = await this.$refs.formz.validate();

      this.loading = true;
      try {
        await createCompanyFile(data);
        this.loading = false;
        await this.$u.modal("添加成功");
        this.$u.back();
      } catch (error) {
        this.loading = false;
      }
    },
  },
};
</script>

<style>
page {
  background: #fff;
}
</style>
